#include "BattleEngine.h"

BattleEngine::BattleEngine(Ui::MainClass* u) {
    ui = u;
    cleanSession = false;

    redUnits = new QList <Unit*> ();
    blueUnits = new QList <Unit*> ();

    for(int i = 0 ; i < 8 ; i++) {
        redBlg[i] = NULL;
        blueBlg[i] = NULL;
    }

    //Initialize amount of money produced by an economic center at level i+1
    for(int i = 0 ; i < 6 ; i++){
        if(i <= 0)
            ecoProd[i] = 30;
        else
            ecoProd[i] = ecoProd[i-1] * 2;
    }

    //Initialize amount of technology produced by a tech center at level i+1
    for(int i = 0 ; i < 3; i++) {
        if(i <= 0)
            techProd[i] = 15;
        else
            techProd[i] = techProd[i-1] * 3;

    }

    cleaner = new QTimer();
    resourceRound = new QTimer();
    selectButtonAnimator = new QTimer();

    highlighted = NULL;

    connect(ui->redSel1,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->redSel2,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->redSel3,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->redSel4,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->redSel5,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->redSel6,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->redSel7,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->redSel8,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel1,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel2,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel3,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel4,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel5,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel6,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel7,SIGNAL(clicked()),this,SLOT(engageSelectButton()));
    connect(ui->blueSel8,SIGNAL(clicked()),this,SLOT(engageSelectButton()));

    connect(selectButtonAnimator,SIGNAL(timeout()),this,SLOT(animateHighlighted()));
    connect(cleaner,SIGNAL(timeout()),this,SLOT(cleanUp()));
    connect(resourceRound,SIGNAL(timeout()),this,SLOT(economyRound()));
    connect(resourceRound,SIGNAL(timeout()),this,SLOT(technologyRound()));

    buildSpriteBase();

}

void BattleEngine::engageSelectButton() {
    QPushButton* btn = (QPushButton *)(QObject::sender());

    if(highlighted != btn) {
        disengageSelectButton();
        highlighted = btn;
        animationIndex = 0;

        selectButtonAnimator->start(100);

        for(int i = 0 ; i < 8 ; i++) {
            if(redBlg[i] != NULL) {
                if(redBlg[i]->getDiplayButton() == btn) {
                    redBlg[i]->select();
                    //redBlg[i]->displayCommands();
                    break;
                }
            }
            else if (blueBlg[i] != NULL) {
                if (blueBlg[i]->getDiplayButton() == btn) {
                    //blueBlg[i]->displayCommands();
                    blueBlg[i]->select();
                    break;
                }
            }
        }

    }
    else
        disengageSelectButton();
}

void BattleEngine::disengageSelectButton() {
    selectButtonAnimator->stop();
    if(highlighted != NULL) {
        highlighted->setIcon(*(iconAnim->value(0)));

        for(int i = 0 ; i < 8 ; i++) {
            if(redBlg[i] != NULL) {
                if(redBlg[i]->getDiplayButton() == highlighted) {
                    redBlg[i]->deselect();
                    //redBlg[i]->displayCommands();
                    break;
                }
            }
            else if (blueBlg[i] != NULL) {
                if (blueBlg[i]->getDiplayButton() == highlighted) {
                    //blueBlg[i]->displayCommands();
                    blueBlg[i]->deselect();
                    break;
                }
            }
        }
    }

    highlighted = NULL;
}

void BattleEngine::animateHighlighted() {
    if(highlighted != NULL) {
        switch(animationIndex) {
            case 0:
                highlighted->setIcon(*(iconAnim->value(1)));
                break;
            case 1:
                highlighted->setIcon(*(iconAnim->value(2)));
                break;
            case 2:
                highlighted->setIcon(*(iconAnim->value(3)));
                break;
            case 3:
                highlighted->setIcon(*(iconAnim->value(4)));
                break;
            case 4:
                highlighted->setIcon(*(iconAnim->value(3)));
                break;
            case 5:
                highlighted->setIcon(*(iconAnim->value(2)));
                break;
            default:
                break; //invalid case
        }
    }

    animationIndex++;

    animationIndex%=6;
}

void BattleEngine::buildSpriteBase() {
    iconAnim = new QList <QIcon*> ();
    iconAnim->append(new QIcon(":Interface/animated/interface/select/0.png"));
    iconAnim->append(new QIcon(":Interface/animated/interface/select/1.png"));
    iconAnim->append(new QIcon(":Interface/animated/interface/select/2.png"));
    iconAnim->append(new QIcon(":Interface/animated/interface/select/3.png"));
    iconAnim->append(new QIcon(":Interface/animated/interface/select/4.png"));

    //Red AIR
    unitSpriteBase[0][0][0][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/walk/1.png"));
    unitSpriteBase[0][0][0][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/walk/2.png"));
    unitSpriteBase[0][0][0][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/walk/3.png"));
    unitSpriteBase[0][0][0][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/walk/4.png"));
    unitSpriteBase[0][0][0][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/attack/1.png"));
    unitSpriteBase[0][0][0][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/attack/2.png"));
    unitSpriteBase[0][0][0][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/attack/3.png"));
    unitSpriteBase[0][0][0][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/attack/4.png"));
    unitSpriteBase[0][0][0][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/steady/1.png"));
    unitSpriteBase[0][0][0][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/steady/2.png"));
    unitSpriteBase[0][0][0][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/steady/3.png"));
    unitSpriteBase[0][0][0][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv1/steady/4.png"));
    unitSpriteBase[0][0][0][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/walk/1.png"));
    unitSpriteBase[0][0][0][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/walk/2.png"));
    unitSpriteBase[0][0][0][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/walk/3.png"));
    unitSpriteBase[0][0][0][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/walk/4.png"));
    unitSpriteBase[0][0][0][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/1.png"));
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/2.png"));
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/3.png"));
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/4.png"));
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/5.png"));
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/6.png"));
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/7.png"));
    unitSpriteBase[0][0][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/attack/8.png"));
    unitSpriteBase[0][0][0][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/steady/1.png"));
    unitSpriteBase[0][0][0][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/steady/2.png"));
    unitSpriteBase[0][0][0][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/steady/3.png"));
    unitSpriteBase[0][0][0][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv2/steady/4.png"));
    unitSpriteBase[0][0][0][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/walk/1.png"));
    unitSpriteBase[0][0][0][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/walk/2.png"));
    unitSpriteBase[0][0][0][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/walk/3.png"));
    unitSpriteBase[0][0][0][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/walk/4.png"));
    unitSpriteBase[0][0][0][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/attack/1.png"));
    unitSpriteBase[0][0][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/attack/2.png"));
    unitSpriteBase[0][0][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/attack/3.png"));
    unitSpriteBase[0][0][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/attack/4.png"));
    unitSpriteBase[0][0][0][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][0][2][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AA/lv3/steady/1.png"));
    unitSpriteBase[0][0][1][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/walk/1.png"));
    unitSpriteBase[0][0][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/walk/2.png"));
    unitSpriteBase[0][0][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/walk/3.png"));
    unitSpriteBase[0][0][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/walk/4.png"));
    unitSpriteBase[0][0][1][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/attack/1.png"));
    unitSpriteBase[0][0][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/attack/2.png"));
    unitSpriteBase[0][0][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/attack/3.png"));
    unitSpriteBase[0][0][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/attack/4.png"));
    unitSpriteBase[0][0][1][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/steady/1.png"));
    unitSpriteBase[0][0][1][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/steady/2.png"));
    unitSpriteBase[0][0][1][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/steady/3.png"));
    unitSpriteBase[0][0][1][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv1/steady/4.png"));
    unitSpriteBase[0][0][1][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/walk/1.png"));
    unitSpriteBase[0][0][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/walk/2.png"));
    unitSpriteBase[0][0][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/walk/3.png"));
    unitSpriteBase[0][0][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/walk/4.png"));
    unitSpriteBase[0][0][1][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/attack/1.png"));
    unitSpriteBase[0][0][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/attack/2.png"));
    unitSpriteBase[0][0][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/attack/3.png"));
    unitSpriteBase[0][0][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/attack/4.png"));
    unitSpriteBase[0][0][1][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/steady/1.png"));
    unitSpriteBase[0][0][1][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/steady/2.png"));
    unitSpriteBase[0][0][1][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/steady/3.png"));
    unitSpriteBase[0][0][1][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv2/steady/4.png"));
    unitSpriteBase[0][0][1][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/walk/1.png"));
    unitSpriteBase[0][0][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/walk/2.png"));
    unitSpriteBase[0][0][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/walk/3.png"));
    unitSpriteBase[0][0][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/walk/4.png"));
    unitSpriteBase[0][0][1][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/attack/1.png"));
    unitSpriteBase[0][0][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/attack/2.png"));
    unitSpriteBase[0][0][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/attack/3.png"));
    unitSpriteBase[0][0][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/attack/4.png"));
    unitSpriteBase[0][0][1][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][1][2][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AI/lv3/steady/1.png"));
    unitSpriteBase[0][0][2][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/walk/1.png"));
    unitSpriteBase[0][0][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/walk/2.png"));
    unitSpriteBase[0][0][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/walk/3.png"));
    unitSpriteBase[0][0][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/walk/4.png"));
    unitSpriteBase[0][0][2][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/attack/1.png"));
    unitSpriteBase[0][0][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/attack/2.png"));
    unitSpriteBase[0][0][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/attack/3.png"));
    unitSpriteBase[0][0][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/attack/4.png"));
    unitSpriteBase[0][0][2][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/steady/1.png"));
    unitSpriteBase[0][0][2][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/steady/2.png"));
    unitSpriteBase[0][0][2][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/steady/3.png"));
    unitSpriteBase[0][0][2][0][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv1/steady/4.png"));
    unitSpriteBase[0][0][2][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/walk/1.png"));
    unitSpriteBase[0][0][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/walk/2.png"));
    unitSpriteBase[0][0][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/walk/3.png"));
    unitSpriteBase[0][0][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/walk/4.png"));
    unitSpriteBase[0][0][2][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/1.png"));
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/2.png"));
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/3.png"));
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/4.png"));
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/1.png"));
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/2.png"));
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/3.png"));
    unitSpriteBase[0][0][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/attack/4.png"));
    unitSpriteBase[0][0][2][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/steady/1.png"));
    unitSpriteBase[0][0][2][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/steady/2.png"));
    unitSpriteBase[0][0][2][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/steady/3.png"));
    unitSpriteBase[0][0][2][1][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv2/steady/4.png"));
    unitSpriteBase[0][0][2][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/walk/1.png"));
    unitSpriteBase[0][0][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/walk/2.png"));
    unitSpriteBase[0][0][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/walk/3.png"));
    unitSpriteBase[0][0][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/walk/4.png"));
    unitSpriteBase[0][0][2][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/attack/1.png"));
    unitSpriteBase[0][0][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/attack/2.png"));
    unitSpriteBase[0][0][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/attack/3.png"));
    unitSpriteBase[0][0][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/attack/4.png"));
    unitSpriteBase[0][0][2][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][0][2][2][2]->append(new QPixmap(":Sprites/animated/Red/Aircraft/AT/lv3/steady/1.png"));

    //Red INF
    unitSpriteBase[0][1][1][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/walk/1.png"));
    unitSpriteBase[0][1][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/walk/2.png"));
    unitSpriteBase[0][1][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/walk/3.png"));
    unitSpriteBase[0][1][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/walk/4.png"));
    unitSpriteBase[0][1][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/walk/5.png"));
    unitSpriteBase[0][1][1][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/attack/1.png"));
    unitSpriteBase[0][1][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/attack/2.png"));
    unitSpriteBase[0][1][1][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][0][2]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv1/steady/1.png"));
    unitSpriteBase[0][1][1][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/walk/1.png"));
    unitSpriteBase[0][1][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/walk/2.png"));
    unitSpriteBase[0][1][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/walk/3.png"));
    unitSpriteBase[0][1][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/walk/4.png"));
    unitSpriteBase[0][1][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/walk/5.png"));
    unitSpriteBase[0][1][1][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/attack/1.png"));
    unitSpriteBase[0][1][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/attack/2.png"));
    unitSpriteBase[0][1][1][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][1][2]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv2/steady/1.png"));
    unitSpriteBase[0][1][1][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/walk/1.png"));
    unitSpriteBase[0][1][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/walk/2.png"));
    unitSpriteBase[0][1][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/walk/3.png"));
    unitSpriteBase[0][1][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/walk/4.png"));
    unitSpriteBase[0][1][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/walk/5.png"));
    unitSpriteBase[0][1][1][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/attack/1.png"));
    unitSpriteBase[0][1][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/attack/2.png"));
    unitSpriteBase[0][1][1][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][1][2][2]->append(new QPixmap(":Sprites/animated/Red/Infantry/AI/lv3/steady/1.png"));
    unitSpriteBase[0][1][2][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/walk/1.png"));
    unitSpriteBase[0][1][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/walk/2.png"));
    unitSpriteBase[0][1][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/walk/3.png"));
    unitSpriteBase[0][1][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/walk/4.png"));
    unitSpriteBase[0][1][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/walk/5.png"));
    unitSpriteBase[0][1][2][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/attack/1.png"));
    unitSpriteBase[0][1][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/attack/2.png"));
    unitSpriteBase[0][1][2][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][0][2]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv1/steady/1.png"));
    unitSpriteBase[0][1][2][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/walk/1.png"));
    unitSpriteBase[0][1][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/walk/2.png"));
    unitSpriteBase[0][1][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/walk/3.png"));
    unitSpriteBase[0][1][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/walk/4.png"));
    unitSpriteBase[0][1][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/walk/5.png"));
    unitSpriteBase[0][1][2][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/attack/1.png"));
    unitSpriteBase[0][1][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/attack/2.png"));
    unitSpriteBase[0][1][2][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][1][2]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv2/steady/1.png"));
    unitSpriteBase[0][1][2][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/walk/1.png"));
    unitSpriteBase[0][1][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/walk/2.png"));
    unitSpriteBase[0][1][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/walk/3.png"));
    unitSpriteBase[0][1][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/walk/4.png"));
    unitSpriteBase[0][1][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/walk/5.png"));
    unitSpriteBase[0][1][2][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/attack/1.png"));
    unitSpriteBase[0][1][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/attack/2.png"));
    unitSpriteBase[0][1][2][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][1][2][2][2]->append(new QPixmap(":Sprites/animated/Red/Infantry/AT/lv3/steady/1.png"));

    //Red VEH
    unitSpriteBase[0][2][0][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][0][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv1/walk/1.png"));
    unitSpriteBase[0][2][0][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][0][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv1/attack/1.png"));
    unitSpriteBase[0][2][0][0][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv1/attack/2.png"));
    unitSpriteBase[0][2][0][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][0][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv1/steady/1.png"));
    unitSpriteBase[0][2][0][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][1][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv2/walk/1.png"));
    unitSpriteBase[0][2][0][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv2/attack/1.png"));
    unitSpriteBase[0][2][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv2/attack/2.png"));
    unitSpriteBase[0][2][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv2/attack/3.png"));
    unitSpriteBase[0][2][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv2/attack/4.png"));
    unitSpriteBase[0][2][0][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv2/attack/5.png"));
    unitSpriteBase[0][2][0][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][1][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv2/steady/1.png"));
    unitSpriteBase[0][2][0][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/walk/1.png"));
    unitSpriteBase[0][2][0][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/1.png"));
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/2.png"));
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/3.png"));
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/4.png"));
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/5.png"));
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/6.png"));
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/7.png"));
    unitSpriteBase[0][2][0][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/attack/8.png"));
    unitSpriteBase[0][2][0][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][0][2][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AA/lv3/steady/1.png"));
    //AI
    unitSpriteBase[0][2][1][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][0][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv1/walk/1.png"));
    unitSpriteBase[0][2][1][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv1/attack/1.png"));
    unitSpriteBase[0][2][1][0][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv1/attack/2.png"));
    unitSpriteBase[0][2][1][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][0][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv1/steady/1.png"));
    unitSpriteBase[0][2][1][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][1][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv2/walk/1.png"));
    unitSpriteBase[0][2][1][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv2/attack/1.png"));
    unitSpriteBase[0][2][1][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv2/attack/2.png"));
    unitSpriteBase[0][2][1][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][1][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv2/steady/1.png"));
    unitSpriteBase[0][2][1][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv3/walk/1.png"));
    unitSpriteBase[0][2][1][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv3/attack/1.png"));
    unitSpriteBase[0][2][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv3/attack/2.png"));
    unitSpriteBase[0][2][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv3/attack/3.png"));
    unitSpriteBase[0][2][1][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv3/attack/4.png"));
    unitSpriteBase[0][2][1][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][1][2][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AI/lv3/steady/1.png"));
    unitSpriteBase[0][2][2][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][0][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv1/walk/1.png"));
    unitSpriteBase[0][2][2][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv1/attack/1.png"));
    unitSpriteBase[0][2][2][0][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv1/attack/2.png"));
    unitSpriteBase[0][2][2][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][0][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv1/steady/1.png"));
    unitSpriteBase[0][2][2][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][1][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv2/walk/1.png"));
    unitSpriteBase[0][2][2][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv2/attack/1.png"));
    unitSpriteBase[0][2][2][1][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv2/attack/2.png"));
    unitSpriteBase[0][2][2][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][1][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv2/steady/1.png"));
    unitSpriteBase[0][2][2][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/1.png"));
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/2.png"));
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/3.png"));
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/4.png"));
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/5.png"));
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/6.png"));
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/7.png"));
    unitSpriteBase[0][2][2][2][0]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/walk/8.png"));
    unitSpriteBase[0][2][2][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/attack/1.png"));
    unitSpriteBase[0][2][2][2][1]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/attack/2.png"));
    unitSpriteBase[0][2][2][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[0][2][2][2][2]->append(new QPixmap(":Sprites/animated/Red/Vehicle/AT/lv3/steady/1.png"));

    //Blue AIR
    unitSpriteBase[1][0][0][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/walk/1.png"));
    unitSpriteBase[1][0][0][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/walk/2.png"));
    unitSpriteBase[1][0][0][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/walk/3.png"));
    unitSpriteBase[1][0][0][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/walk/4.png"));
    unitSpriteBase[1][0][0][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/attack/1.png"));
    unitSpriteBase[1][0][0][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/attack/2.png"));
    unitSpriteBase[1][0][0][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/attack/3.png"));
    unitSpriteBase[1][0][0][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/attack/4.png"));
    unitSpriteBase[1][0][0][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/steady/1.png"));
    unitSpriteBase[1][0][0][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/steady/2.png"));
    unitSpriteBase[1][0][0][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/steady/3.png"));
    unitSpriteBase[1][0][0][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv1/steady/4.png"));
    unitSpriteBase[1][0][0][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/walk/1.png"));
    unitSpriteBase[1][0][0][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/walk/2.png"));
    unitSpriteBase[1][0][0][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/walk/3.png"));
    unitSpriteBase[1][0][0][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/walk/4.png"));
    unitSpriteBase[1][0][0][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/1.png"));
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/2.png"));
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/3.png"));
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/4.png"));
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/5.png"));
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/6.png"));
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/7.png"));
    unitSpriteBase[1][0][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/attack/8.png"));
    unitSpriteBase[1][0][0][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/steady/1.png"));
    unitSpriteBase[1][0][0][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/steady/2.png"));
    unitSpriteBase[1][0][0][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/steady/3.png"));
    unitSpriteBase[1][0][0][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv2/steady/4.png"));
    unitSpriteBase[1][0][0][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/walk/1.png"));
    unitSpriteBase[1][0][0][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/walk/2.png"));
    unitSpriteBase[1][0][0][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/walk/3.png"));
    unitSpriteBase[1][0][0][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/walk/4.png"));
    unitSpriteBase[1][0][0][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/attack/1.png"));
    unitSpriteBase[1][0][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/attack/2.png"));
    unitSpriteBase[1][0][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/attack/3.png"));
    unitSpriteBase[1][0][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/attack/4.png"));
    unitSpriteBase[1][0][0][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][0][2][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AA/lv3/steady/1.png"));
    unitSpriteBase[1][0][1][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/walk/1.png"));
    unitSpriteBase[1][0][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/walk/2.png"));
    unitSpriteBase[1][0][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/walk/3.png"));
    unitSpriteBase[1][0][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/walk/4.png"));
    unitSpriteBase[1][0][1][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/attack/1.png"));
    unitSpriteBase[1][0][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/attack/2.png"));
    unitSpriteBase[1][0][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/attack/3.png"));
    unitSpriteBase[1][0][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/attack/4.png"));
    unitSpriteBase[1][0][1][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/steady/1.png"));
    unitSpriteBase[1][0][1][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/steady/2.png"));
    unitSpriteBase[1][0][1][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/steady/3.png"));
    unitSpriteBase[1][0][1][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv1/steady/4.png"));
    unitSpriteBase[1][0][1][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/walk/1.png"));
    unitSpriteBase[1][0][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/walk/2.png"));
    unitSpriteBase[1][0][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/walk/3.png"));
    unitSpriteBase[1][0][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/walk/4.png"));
    unitSpriteBase[1][0][1][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/attack/1.png"));
    unitSpriteBase[1][0][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/attack/2.png"));
    unitSpriteBase[1][0][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/attack/3.png"));
    unitSpriteBase[1][0][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/attack/4.png"));
    unitSpriteBase[1][0][1][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/steady/1.png"));
    unitSpriteBase[1][0][1][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/steady/2.png"));
    unitSpriteBase[1][0][1][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/steady/3.png"));
    unitSpriteBase[1][0][1][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv2/steady/4.png"));
    unitSpriteBase[1][0][1][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/walk/1.png"));
    unitSpriteBase[1][0][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/walk/2.png"));
    unitSpriteBase[1][0][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/walk/3.png"));
    unitSpriteBase[1][0][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/walk/4.png"));
    unitSpriteBase[1][0][1][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/attack/1.png"));
    unitSpriteBase[1][0][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/attack/2.png"));
    unitSpriteBase[1][0][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/attack/3.png"));
    unitSpriteBase[1][0][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/attack/4.png"));
    unitSpriteBase[1][0][1][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][1][2][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AI/lv3/steady/1.png"));
    unitSpriteBase[1][0][2][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/walk/1.png"));
    unitSpriteBase[1][0][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/walk/2.png"));
    unitSpriteBase[1][0][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/walk/3.png"));
    unitSpriteBase[1][0][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/walk/4.png"));
    unitSpriteBase[1][0][2][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/attack/1.png"));
    unitSpriteBase[1][0][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/attack/2.png"));
    unitSpriteBase[1][0][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/attack/3.png"));
    unitSpriteBase[1][0][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/attack/4.png"));
    unitSpriteBase[1][0][2][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/steady/1.png"));
    unitSpriteBase[1][0][2][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/steady/2.png"));
    unitSpriteBase[1][0][2][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/steady/3.png"));
    unitSpriteBase[1][0][2][0][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv1/steady/4.png"));
    unitSpriteBase[1][0][2][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/walk/1.png"));
    unitSpriteBase[1][0][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/walk/2.png"));
    unitSpriteBase[1][0][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/walk/3.png"));
    unitSpriteBase[1][0][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/walk/4.png"));
    unitSpriteBase[1][0][2][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/1.png"));
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/2.png"));
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/3.png"));
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/4.png"));
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/1.png"));
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/2.png"));
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/3.png"));
    unitSpriteBase[1][0][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/attack/4.png"));
    unitSpriteBase[1][0][2][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/steady/1.png"));
    unitSpriteBase[1][0][2][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/steady/2.png"));
    unitSpriteBase[1][0][2][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/steady/3.png"));
    unitSpriteBase[1][0][2][1][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv2/steady/4.png"));
    unitSpriteBase[1][0][2][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/walk/1.png"));
    unitSpriteBase[1][0][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/walk/2.png"));
    unitSpriteBase[1][0][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/walk/3.png"));
    unitSpriteBase[1][0][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/walk/4.png"));
    unitSpriteBase[1][0][2][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/attack/1.png"));
    unitSpriteBase[1][0][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/attack/2.png"));
    unitSpriteBase[1][0][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/attack/3.png"));
    unitSpriteBase[1][0][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/attack/4.png"));
    unitSpriteBase[1][0][2][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][0][2][2][2]->append(new QPixmap(":Sprites/animated/Blue/Aircraft/AT/lv3/steady/1.png"));

    //Blue INF
    unitSpriteBase[1][1][1][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/walk/1.png"));
    unitSpriteBase[1][1][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/walk/2.png"));
    unitSpriteBase[1][1][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/walk/3.png"));
    unitSpriteBase[1][1][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/walk/4.png"));
    unitSpriteBase[1][1][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/walk/5.png"));
    unitSpriteBase[1][1][1][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/attack/1.png"));
    unitSpriteBase[1][1][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/attack/2.png"));
    unitSpriteBase[1][1][1][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][0][2]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv1/steady/1.png"));
    unitSpriteBase[1][1][1][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/walk/1.png"));
    unitSpriteBase[1][1][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/walk/2.png"));
    unitSpriteBase[1][1][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/walk/3.png"));
    unitSpriteBase[1][1][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/walk/4.png"));
    unitSpriteBase[1][1][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/walk/5.png"));
    unitSpriteBase[1][1][1][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/attack/1.png"));
    unitSpriteBase[1][1][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/attack/2.png"));
    unitSpriteBase[1][1][1][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][1][2]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv2/steady/1.png"));
    unitSpriteBase[1][1][1][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/walk/1.png"));
    unitSpriteBase[1][1][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/walk/2.png"));
    unitSpriteBase[1][1][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/walk/3.png"));
    unitSpriteBase[1][1][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/walk/4.png"));
    unitSpriteBase[1][1][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/walk/5.png"));
    unitSpriteBase[1][1][1][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/attack/1.png"));
    unitSpriteBase[1][1][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/attack/2.png"));
    unitSpriteBase[1][1][1][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][1][2][2]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AI/lv3/steady/1.png"));
    unitSpriteBase[1][1][2][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/walk/1.png"));
    unitSpriteBase[1][1][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/walk/2.png"));
    unitSpriteBase[1][1][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/walk/3.png"));
    unitSpriteBase[1][1][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/walk/4.png"));
    unitSpriteBase[1][1][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/walk/5.png"));
    unitSpriteBase[1][1][2][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/attack/1.png"));
    unitSpriteBase[1][1][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/attack/2.png"));
    unitSpriteBase[1][1][2][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][0][2]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv1/steady/1.png"));
    unitSpriteBase[1][1][2][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/walk/1.png"));
    unitSpriteBase[1][1][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/walk/2.png"));
    unitSpriteBase[1][1][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/walk/3.png"));
    unitSpriteBase[1][1][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/walk/4.png"));
    unitSpriteBase[1][1][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/walk/5.png"));
    unitSpriteBase[1][1][2][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/attack/1.png"));
    unitSpriteBase[1][1][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/attack/2.png"));
    unitSpriteBase[1][1][2][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][1][2]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv2/steady/1.png"));
    unitSpriteBase[1][1][2][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/walk/1.png"));
    unitSpriteBase[1][1][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/walk/2.png"));
    unitSpriteBase[1][1][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/walk/3.png"));
    unitSpriteBase[1][1][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/walk/4.png"));
    unitSpriteBase[1][1][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/walk/5.png"));
    unitSpriteBase[1][1][2][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/attack/1.png"));
    unitSpriteBase[1][1][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/attack/2.png"));
    unitSpriteBase[1][1][2][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][1][2][2][2]->append(new QPixmap(":Sprites/animated/Blue/Infantry/AT/lv3/steady/1.png"));

    //Blue VEH
    unitSpriteBase[1][2][0][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][0][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv1/walk/1.png"));
    unitSpriteBase[1][2][0][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][0][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv1/attack/1.png"));
    unitSpriteBase[1][2][0][0][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv1/attack/2.png"));
    unitSpriteBase[1][2][0][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][0][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv1/steady/1.png"));
    unitSpriteBase[1][2][0][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][1][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv2/walk/1.png"));
    unitSpriteBase[1][2][0][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv2/attack/1.png"));
    unitSpriteBase[1][2][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv2/attack/2.png"));
    unitSpriteBase[1][2][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv2/attack/3.png"));
    unitSpriteBase[1][2][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv2/attack/4.png"));
    unitSpriteBase[1][2][0][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv2/attack/5.png"));
    unitSpriteBase[1][2][0][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][1][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv2/steady/1.png"));
    unitSpriteBase[1][2][0][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/walk/1.png"));
    unitSpriteBase[1][2][0][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/1.png"));
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/2.png"));
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/3.png"));
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/4.png"));
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/5.png"));
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/6.png"));
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/7.png"));
    unitSpriteBase[1][2][0][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/attack/8.png"));
    unitSpriteBase[1][2][0][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][0][2][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AA/lv3/steady/1.png"));
    //AI
    unitSpriteBase[1][2][1][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][0][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv1/walk/1.png"));
    unitSpriteBase[1][2][1][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv1/attack/1.png"));
    unitSpriteBase[1][2][1][0][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv1/attack/2.png"));
    unitSpriteBase[1][2][1][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][0][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv1/steady/1.png"));
    unitSpriteBase[1][2][1][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][1][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv2/walk/1.png"));
    unitSpriteBase[1][2][1][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv2/attack/1.png"));
    unitSpriteBase[1][2][1][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv2/attack/2.png"));
    unitSpriteBase[1][2][1][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][1][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv2/steady/1.png"));
    unitSpriteBase[1][2][1][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv3/walk/1.png"));
    unitSpriteBase[1][2][1][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv3/attack/1.png"));
    unitSpriteBase[1][2][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv3/attack/2.png"));
    unitSpriteBase[1][2][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv3/attack/3.png"));
    unitSpriteBase[1][2][1][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv3/attack/4.png"));
    unitSpriteBase[1][2][1][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][1][2][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AI/lv3/steady/1.png"));
    unitSpriteBase[1][2][2][0][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][0][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv1/walk/1.png"));
    unitSpriteBase[1][2][2][0][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv1/attack/1.png"));
    unitSpriteBase[1][2][2][0][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv1/attack/2.png"));
    unitSpriteBase[1][2][2][0][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][0][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv1/steady/1.png"));
    unitSpriteBase[1][2][2][1][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][1][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv2/walk/1.png"));
    unitSpriteBase[1][2][2][1][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv2/attack/1.png"));
    unitSpriteBase[1][2][2][1][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv2/attack/2.png"));
    unitSpriteBase[1][2][2][1][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][1][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv2/steady/1.png"));
    unitSpriteBase[1][2][2][2][0] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/1.png"));
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/2.png"));
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/3.png"));
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/4.png"));
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/5.png"));
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/6.png"));
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/7.png"));
    unitSpriteBase[1][2][2][2][0]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/walk/8.png"));
    unitSpriteBase[1][2][2][2][1] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/attack/1.png"));
    unitSpriteBase[1][2][2][2][1]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/attack/2.png"));
    unitSpriteBase[1][2][2][2][2] = new QList <QPixmap*> ();
    unitSpriteBase[1][2][2][2][2]->append(new QPixmap(":Sprites/animated/Blue/Vehicle/AT/lv3/steady/1.png"));

    blgSpriteBase[0][0][0][0] = new QPixmap(":Sprites/animated/Red/Building/Capitol/lv1.png");
    blgSpriteBase[0][0][0][1] = new QPixmap(":Sprites/animated/Red/Building/Capitol/lv1ON.png");
    blgSpriteBase[0][0][1][0] = new QPixmap(":Sprites/animated/Red/Building/Capitol/lv2.png");
    blgSpriteBase[0][0][1][1] = new QPixmap(":Sprites/animated/Red/Building/Capitol/lv2ON.png");
    blgSpriteBase[0][0][2][0] = new QPixmap(":Sprites/animated/Red/Building/Capitol/lv3.png");
    blgSpriteBase[0][0][2][1] = new QPixmap(":Sprites/animated/Red/Building/Capitol/lv3ON.png");
    blgSpriteBase[0][1][0][0] = new QPixmap(":Sprites/animated/Red/Building/Barracks/lv1.png");
    blgSpriteBase[0][1][0][1] = new QPixmap(":Sprites/animated/Red/Building/Barracks/lv1ON.png");
    blgSpriteBase[0][1][1][0] = new QPixmap(":Sprites/animated/Red/Building/Barracks/lv2.png");
    blgSpriteBase[0][1][1][1] = new QPixmap(":Sprites/animated/Red/Building/Barracks/lv2ON.png");
    blgSpriteBase[0][1][2][0] = new QPixmap(":Sprites/animated/Red/Building/Barracks/lv3.png");
    blgSpriteBase[0][1][2][1] = new QPixmap(":Sprites/animated/Red/Building/Barracks/lv3ON.png");
    blgSpriteBase[0][2][0][0] = new QPixmap(":Sprites/animated/Red/Building/Warfactory/lv1.png");
    blgSpriteBase[0][2][0][1] = new QPixmap(":Sprites/animated/Red/Building/Warfactory/lv1ON.png");
    blgSpriteBase[0][2][1][0] = new QPixmap(":Sprites/animated/Red/Building/Warfactory/lv2.png");
    blgSpriteBase[0][2][1][1] = new QPixmap(":Sprites/animated/Red/Building/Warfactory/lv2ON.png");
    blgSpriteBase[0][2][2][0] = new QPixmap(":Sprites/animated/Red/Building/Warfactory/lv3.png");
    blgSpriteBase[0][2][2][1] = new QPixmap(":Sprites/animated/Red/Building/Warfactory/lv3ON.png");
    blgSpriteBase[0][3][0][0] = new QPixmap(":Sprites/animated/Red/Building/Airfield/lv1.png");
    blgSpriteBase[0][3][0][1] = new QPixmap(":Sprites/animated/Red/Building/Airfield/lv1ON.png");
    blgSpriteBase[0][3][1][0] = new QPixmap(":Sprites/animated/Red/Building/Airfield/lv2.png");
    blgSpriteBase[0][3][1][1] = new QPixmap(":Sprites/animated/Red/Building/Airfield/lv2ON.png");
    blgSpriteBase[0][3][2][0] = new QPixmap(":Sprites/animated/Red/Building/Airfield/lv3.png");
    blgSpriteBase[0][3][2][1] = new QPixmap(":Sprites/animated/Red/Building/Airfield/lv3ON.png");
    blgSpriteBase[0][4][0][0] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv1.png");
    blgSpriteBase[0][4][0][1] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv1ON.png");
    blgSpriteBase[0][4][1][0] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv2.png");
    blgSpriteBase[0][4][1][1] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv2ON.png");
    blgSpriteBase[0][4][2][0] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv3.png");
    blgSpriteBase[0][4][2][1] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv3ON.png");
    blgSpriteBase[0][4][3][0] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv4.png");
    blgSpriteBase[0][4][3][1] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv4ON.png");
    blgSpriteBase[0][4][4][0] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv5.png");
    blgSpriteBase[0][4][4][1] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv5ON.png");
    blgSpriteBase[0][4][5][0] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv6.png");
    blgSpriteBase[0][4][5][1] = new QPixmap(":Sprites/animated/Red/Building/EconomicCenter/lv6ON.png");
    blgSpriteBase[0][5][0][0] = new QPixmap(":Sprites/animated/Red/Building/TechCenter/lv1.png");
    blgSpriteBase[0][5][0][1] = new QPixmap(":Sprites/animated/Red/Building/TechCenter/lv1ON.png");
    blgSpriteBase[0][5][1][0] = new QPixmap(":Sprites/animated/Red/Building/TechCenter/lv2.png");
    blgSpriteBase[0][5][1][1] = new QPixmap(":Sprites/animated/Red/Building/TechCenter/lv2ON.png");
    blgSpriteBase[0][5][2][0] = new QPixmap(":Sprites/animated/Red/Building/TechCenter/lv3.png");
    blgSpriteBase[0][5][2][1] = new QPixmap(":Sprites/animated/Red/Building/TechCenter/lv3ON.png");
    blgSpriteBase[0][5][3][0] = new QPixmap(":Sprites/animated/Red/Building/Superweapon/lv1.png");
    blgSpriteBase[0][5][3][1] = new QPixmap(":Sprites/animated/Red/Building/Superweapon/lv1ON.png");

    blgSpriteBase[1][0][0][0] = new QPixmap(":Sprites/animated/Blue/Building/Capitol/lv1.png");
    blgSpriteBase[1][0][0][1] = new QPixmap(":Sprites/animated/Blue/Building/Capitol/lv1ON.png");
    blgSpriteBase[1][0][1][0] = new QPixmap(":Sprites/animated/Blue/Building/Capitol/lv2.png");
    blgSpriteBase[1][0][1][1] = new QPixmap(":Sprites/animated/Blue/Building/Capitol/lv2ON.png");
    blgSpriteBase[1][0][2][0] = new QPixmap(":Sprites/animated/Blue/Building/Capitol/lv3.png");
    blgSpriteBase[1][0][2][1] = new QPixmap(":Sprites/animated/Blue/Building/Capitol/lv3ON.png");
    blgSpriteBase[1][1][0][0] = new QPixmap(":Sprites/animated/Blue/Building/Barracks/lv1.png");
    blgSpriteBase[1][1][0][1] = new QPixmap(":Sprites/animated/Blue/Building/Barracks/lv1ON.png");
    blgSpriteBase[1][1][1][0] = new QPixmap(":Sprites/animated/Blue/Building/Barracks/lv2.png");
    blgSpriteBase[1][1][1][1] = new QPixmap(":Sprites/animated/Blue/Building/Barracks/lv2ON.png");
    blgSpriteBase[1][1][2][0] = new QPixmap(":Sprites/animated/Blue/Building/Barracks/lv3.png");
    blgSpriteBase[1][1][2][1] = new QPixmap(":Sprites/animated/Blue/Building/Barracks/lv3ON.png");
    blgSpriteBase[1][2][0][0] = new QPixmap(":Sprites/animated/Blue/Building/Warfactory/lv1.png");
    blgSpriteBase[1][2][0][1] = new QPixmap(":Sprites/animated/Blue/Building/Warfactory/lv1ON.png");
    blgSpriteBase[1][2][1][0] = new QPixmap(":Sprites/animated/Blue/Building/Warfactory/lv2.png");
    blgSpriteBase[1][2][1][1] = new QPixmap(":Sprites/animated/Blue/Building/Warfactory/lv2ON.png");
    blgSpriteBase[1][2][2][0] = new QPixmap(":Sprites/animated/Blue/Building/Warfactory/lv3.png");
    blgSpriteBase[1][2][2][1] = new QPixmap(":Sprites/animated/Blue/Building/Warfactory/lv3ON.png");
    blgSpriteBase[1][3][0][0] = new QPixmap(":Sprites/animated/Blue/Building/Airfield/lv1.png");
    blgSpriteBase[1][3][0][1] = new QPixmap(":Sprites/animated/Blue/Building/Airfield/lv1ON.png");
    blgSpriteBase[1][3][1][0] = new QPixmap(":Sprites/animated/Blue/Building/Airfield/lv2.png");
    blgSpriteBase[1][3][1][1] = new QPixmap(":Sprites/animated/Blue/Building/Airfield/lv2ON.png");
    blgSpriteBase[1][3][2][0] = new QPixmap(":Sprites/animated/Blue/Building/Airfield/lv3.png");
    blgSpriteBase[1][3][2][1] = new QPixmap(":Sprites/animated/Blue/Building/Airfield/lv3ON.png");
    blgSpriteBase[1][4][0][0] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv1.png");
    blgSpriteBase[1][4][0][1] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv1ON.png");
    blgSpriteBase[1][4][1][0] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv2.png");
    blgSpriteBase[1][4][1][1] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv2ON.png");
    blgSpriteBase[1][4][2][0] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv3.png");
    blgSpriteBase[1][4][2][1] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv3ON.png");
    blgSpriteBase[1][4][3][0] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv4.png");
    blgSpriteBase[1][4][3][1] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv4ON.png");
    blgSpriteBase[1][4][4][0] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv5.png");
    blgSpriteBase[1][4][4][1] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv5ON.png");
    blgSpriteBase[1][4][5][0] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv6.png");
    blgSpriteBase[1][4][5][1] = new QPixmap(":Sprites/animated/Blue/Building/EconomicCenter/lv6ON.png");
    blgSpriteBase[1][5][0][0] = new QPixmap(":Sprites/animated/Blue/Building/TechCenter/lv1.png");
    blgSpriteBase[1][5][0][1] = new QPixmap(":Sprites/animated/Blue/Building/TechCenter/lv1ON.png");
    blgSpriteBase[1][5][1][0] = new QPixmap(":Sprites/animated/Blue/Building/TechCenter/lv2.png");
    blgSpriteBase[1][5][1][1] = new QPixmap(":Sprites/animated/Blue/Building/TechCenter/lv2ON.png");
    blgSpriteBase[1][5][2][0] = new QPixmap(":Sprites/animated/Blue/Building/TechCenter/lv3.png");
    blgSpriteBase[1][5][2][1] = new QPixmap(":Sprites/animated/Blue/Building/TechCenter/lv3ON.png");
    blgSpriteBase[1][5][3][0] = new QPixmap(":Sprites/animated/Blue/Building/Superweapon/lv1.png");
    blgSpriteBase[1][5][3][1] = new QPixmap(":Sprites/animated/Blue/Building/Superweapon/lv1ON.png");
}
void BattleEngine::gameStart() {
    //clear out previous buildings from previous game
    //set default values
    //spawn default buildings for both sides
    playerIsRed = true;
    cleaner->start(1);
    resourceRound->start(1000);
}

bool BattleEngine::unitCanAttackUnit(Unit* base, Unit* target) {
    if (!QString::compare(base->getAttackType(),"AA")) {
        if (!QString::compare(target->getDefenseType(),"Air")) {
            return true;
        }
    }
    else if (QString::compare(base->getAttackType(),"AA")) {
        if (QString::compare(target->getDefenseType(),"Air")) {
            return true;
        }
    }
    else
        return false;

    return false;
}

QList <Unit*>* BattleEngine::getAttackableEnemyUnits(Unit *base) {
    QList <Unit*>* temp = new QList <Unit*> ();
    if(base->getFaction()) {
        for(int i = 0 ; i < blueUnits->size() ; i++) {
            if((blueUnits->value(i)->getPosition() - base->getPosition()) < base->getAttackRange()
                &&
               (blueUnits->value(i)->getPosition() - base->getPosition()) > 0
                &&
                unitCanAttackUnit(base,blueUnits->value(i)))
                temp->append(blueUnits->value(i));
        }
    }
    else if(!(base->getFaction())) {
        for(int i = 0 ; i < redUnits->size() ; i++) {
            if((base->getPosition() - redUnits->value(i)->getPosition()) < base->getAttackRange()
                &&
               (base->getPosition() - redUnits->value(i)->getPosition()) > 0
                &&
                unitCanAttackUnit(base,redUnits->value(i)))
                temp->append(redUnits->value(i));
        }
    }
    return temp;

}

Unit* BattleEngine::getNearestEnemyUnitFromSet(Unit* base, QList<Unit*>* set){
    Unit* nearestEnemyUnit = set->value(0);

    if(base->getFaction()) {
        for(int i = 0 ; i < set->size() ; i++) {
            if(set->value(i)->getPosition() - base->getPosition() <
                nearestEnemyUnit->getPosition() - base->getPosition()) {
                nearestEnemyUnit = set->value(i);
            }
        }
        return nearestEnemyUnit;
    }
    else if(!base->getFaction()) {
        for(int i = 0 ; i < set->size() ; i++) {
            if(base->getPosition() - set->value(i)->getPosition() <
                base->getPosition() - nearestEnemyUnit->getPosition()){
                nearestEnemyUnit = set->value(i);
            }
        }
        return nearestEnemyUnit;
    }
    else
        return NULL;

    return NULL;
}

bool BattleEngine::anyAttackableEnemyUnitsInRange(Unit *base) {
    if(!(getAttackableEnemyUnits(base)->size()))
        return false;
    else
        return true;

    return false;
}

void BattleEngine::spawnUnit(QString defType, QString atkType, int level, bool isRed) {
    Unit* newUnit = NULL;
    int color = 1;
    int def;
    int atk;

    if(isRed)
        color = 0;

    if(!(atkType.compare("AA")))
        atk = 0;
    else if(!(atkType.compare("AI")))
        atk = 1;
    else if(!(atkType.compare("AT")))
        atk = 2;

    if(!(defType.compare("Air"))) {
        def = 0;
        if(!(atkType.compare("AA"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,169,68,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,236,118,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,235,89,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else if(!(atkType.compare("AI"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,184,65,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,189,91,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,163,93,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else if(!(atkType.compare("AT"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,157,105,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,242,126,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(true,isRed,10,100,100,200,30,224,178,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else
            ; //invalid attack type
    }
    else if(!(defType.compare("Infantry"))) {
        def = 1;
        if(!(atkType.compare("AI"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(false,isRed,10,100,15,200,30,31,31,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(false,isRed,10,100,15,200,30,31,31,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(false,isRed,10,100,15,200,30,31,31,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else if(!(atkType.compare("AT"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(false,isRed,10,100,15,200,30,31,31,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(false,isRed,10,100,15,200,30,31,31,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(false,isRed,10,100,15,200,30,31,31,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else
            ; //invalid attack type
    }
    else if(!(defType.compare("Vehicle"))) {
        def = 2;
        if(!(atkType.compare("AA"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,90,61,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,140,95,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,162,121,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else if(!(atkType.compare("AI"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,37,37,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,110,50,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,209,77,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else if(!(atkType.compare("AT"))) {
            switch(level) {
                case 1:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,125,53,100,atkType,defType,this,ui);
                    break;
                case 2:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,209,79,100,atkType,defType,this,ui);
                    break;
                case 3:
                    newUnit = new Unit(false,isRed,10,100,20,200,30,238,141,100,atkType,defType,this,ui);
                    break;
                default:
                    break; //invalid level
            }
        }
        else
            ; //invalid attack type
    }
    else
        ; //invalid defType


    if(isRed && newUnit != NULL)
        redUnits->append(newUnit);
    else if(newUnit != NULL)
        blueUnits->append(newUnit);
    else
        qDebug("NULL POINTER EXCEPTION");

    if(newUnit != NULL) {
        newUnit->buildSpriteBase(unitSpriteBase[color][def][atk][level - 1][0],unitSpriteBase[color][def][atk][level - 1][1],unitSpriteBase[color][def][atk][level - 1][2]);
        newUnit->wakeUnit();
    }

}

void BattleEngine::spawnBuilding(QString type, int slot, int isRed) {
    int color = 1;
    if(isRed)
        color = 0;

    if(!(type.compare("CommandCenter"))) {
        if(isRed && redBlg[slot-1] == NULL) {
            redBlg[slot-1] = new Building(blgSpriteBase[color][0][0][1],blgSpriteBase[color][0][0][0],"CommandCenter 1","",isRed,slot,this,ui);
            qDebug("CC!");
            redBlg[slot-1]->addCmd(iconAnim->value(1),iconAnim->value(0),"Test","Test","spawn unit air aa lv1 red",true);
            redBlg[slot-1]->addCmd(iconAnim->value(1),iconAnim->value(0),"Test","Test","spawn unit air aa lv1 blue",true);
            redBlg[slot-1]->addCmd(iconAnim->value(1),iconAnim->value(0),"Test","Test","spawn unit air aa lv1 blue",true);
        }
        else if (!isRed && blueBlg[slot-1] == NULL)
            blueBlg[slot-1] = new Building(blgSpriteBase[color][0][0][1],blgSpriteBase[color][0][0][0],"CommandCenter 1","",isRed,slot,this,ui);
    }
    else if(!(type.compare("Barracks"))) {
        if(isRed && redBlg[slot-1] == NULL)
            redBlg[slot-1] = new Building(blgSpriteBase[color][1][0][1],blgSpriteBase[color][1][0][0],"Barracks 1","",isRed,slot,this,ui);
        else if (!isRed && blueBlg[slot-1] == NULL)
            blueBlg[slot-1] = new Building(blgSpriteBase[color][1][0][1],blgSpriteBase[color][1][0][0],"Barracks 1","",isRed,slot,this,ui);
    }
    else if(!(type.compare("Warfactory"))) {
        if(isRed && redBlg[slot-1] == NULL)
            redBlg[slot-1] = new Building(blgSpriteBase[color][2][0][1],blgSpriteBase[color][2][0][0],"Warfactory 1","",isRed,slot,this,ui);
        else if (!isRed && blueBlg[slot-1] == NULL)
            blueBlg[slot-1] = new Building(blgSpriteBase[color][2][0][1],blgSpriteBase[color][2][0][0],"Warfactory 1","",isRed,slot,this,ui);
    }
    else if(!(type.compare("Airfield"))) {
        if(isRed && redBlg[slot-1] == NULL)
            redBlg[slot-1] = new Building(blgSpriteBase[color][3][0][1],blgSpriteBase[color][3][0][0],"Airfield 1","",isRed,slot,this,ui);
        else if (!isRed && blueBlg[slot-1] == NULL)
            blueBlg[slot-1] = new Building(blgSpriteBase[color][3][0][1],blgSpriteBase[color][3][0][0],"Airfield 1","",isRed,slot,this,ui);
    }
    else if(!(type.compare("EconomicC"))) {
        if(isRed && redBlg[slot-1] == NULL)
            redBlg[slot-1] = new Building(blgSpriteBase[color][4][0][1],blgSpriteBase[color][4][0][0],"EconomicC 1","",isRed,slot,this,ui);
        else if (!isRed && blueBlg[slot-1] == NULL)
            blueBlg[slot-1] = new Building(blgSpriteBase[color][4][0][1],blgSpriteBase[color][4][0][0],"EconomicC 1","",isRed,slot,this,ui);
    }
    else if(!(type.compare("TechnologyC"))) {
        if(isRed && redBlg[slot-1] == NULL)
            redBlg[slot-1] = new Building(blgSpriteBase[color][5][0][1],blgSpriteBase[color][5][0][0],"TechnologyC 1","",isRed,slot,this,ui);
        else if (!isRed && blueBlg[slot-1] == NULL)
            blueBlg[slot-1] = new Building(blgSpriteBase[color][5][0][1],blgSpriteBase[color][5][0][0],"TechnologyC 1","",isRed,slot,this,ui);
    }

}

void BattleEngine::deselectAllRedBuildings() {
    //Red Buildings
    for(int i = 0 ; i < 8 ; i++) {
        if(redBlg[i] != NULL)
            redBlg[i]->deselect();
    }
}

void BattleEngine::deselectAllBlueBuildings() {
    //Blue Buildings
    for(int i = 0 ; i < 8 ; i++) {
        if(blueBlg[i] != NULL)
            blueBlg[i]->deselect();
    }
}

void BattleEngine::economyRound() {
    for(int i = 0 ; i < 8 ; i++) {
        if(redBlg[i] != NULL) {
            if(!QString::compare(redBlg[i]->getName(),"EconomicC"))
                redMoney += ecoProd[redBlg[i]->getLevel() - 1];
            else if(!QString::compare(redBlg[i]->getName(),"CommandCenter"))
                redMoney += 50 * redBlg[i]->getLevel();
            else
                ; //do nothing
        }

        if(blueBlg[i] != NULL) {
            if(!QString::compare(blueBlg[i]->getName(),"EconomicC"))
                blueMoney += ecoProd[blueBlg[i]->getLevel() - 1];
            else if(!QString::compare(blueBlg[i]->getName(),"CommandCenter"))
                blueMoney += 50 * blueBlg[i]->getLevel();
            else
                ; //do nothing
        }
    }
}

void BattleEngine::technologyRound() {
    for(int i = 0 ; i < 8 ; i++) {
        if(redBlg[i] != NULL) {
            if(!QString::compare(redBlg[i]->getName(),"TechnologyC"))
                redTech += techProd[redBlg[i]->getLevel() - 1];
            else if(!QString::compare(redBlg[i]->getName(),"CommandCenter"))
                redTech += 15 * redBlg[i]->getLevel();
            else
                ; //do nothing
        }

        if(blueBlg[i] != NULL) {
            if(!QString::compare(blueBlg[i]->getName(),"TechnologyC"))
                blueTech += techProd[blueBlg[i]->getLevel() - 1];
            else if(!QString::compare(blueBlg[i]->getName(),"CommandCenter"))
                blueTech += 15 * blueBlg[i]->getLevel();
            else
                ; //do nothing
        }
    }
}


void BattleEngine::cleanUp() {
    if(!cleanSession) {
        cleanSession = true;
        bool blueFlag = true;
        bool redFlag = true;
        Unit* deleteThis;
        while(redFlag) {
            redFlag = false;
            for(int i = 0 ; i < redUnits->size() && !redFlag ; i++){
                if(redUnits->value(i)->getHP() <= 0 && !redFlag) {
                    deleteThis = redUnits->value(i);
                    deleteThis->freeze();
                    redUnits->removeAt(i);
                    //deleteThis->deleteLater();
                    //deleteThis->~Unit();

                    redFlag = true;
                    break;
                }
            }
        }

        while(blueFlag) {
            blueFlag = false;
            for(int i = 0 ; i < blueUnits->size() && !blueFlag; i++){
                if(blueUnits->value(i)->getHP() <= 0 && !blueFlag) {
                    deleteThis = blueUnits->value(i);
                    deleteThis->freeze();
                    blueUnits->removeAt(i);
                    //deleteThis->deleteLater();
                    //deleteThis->~Unit();

                    blueFlag = true;
                    break;
                }
            }
        }
        cleanSession = false;
    }

}

QPoint* BattleEngine::vectorXY(int magnitude, int angle, int baseX, int baseY){
    return new QPoint(baseX + (magnitude * cos((double)angle * 0.0174532925)), baseY - (magnitude * sin((double)angle * 0.0174532925)));
}

void BattleEngine::spawnInfLv1() {
    //spawnUnit("Air","AI",1,true);
    //spawnUnit("Infantry","AT",3,false);
}

void BattleEngine::commandInterface() {
    qDebug("SPAWN!");
    Command* btn = (Command*)QObject::sender();
    if(btn->getType().contains("spawn")){
        if(btn->getType().contains("unit")) {
            if(btn->getType().contains("air")) {
                if(btn->getType().contains("aa")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AA",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AA",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AA",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AA",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AA",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AA",3,false);
                    }
                    else
                        ; //invalid unit type
                }
                else if(btn->getType().contains("ai")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AI",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AI",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AI",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AI",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AI",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AI",3,false);
                    }
                    else
                        ; //invalid unit type
                }
                else if(btn->getType().contains("at")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AT",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AT",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AT",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AT",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Air","AT",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Air","AT",3,false);
                    }
                    else
                        ; //invalid unit type

                }
                else
                    ; //invalid unit type
            }
            else if(btn->getType().contains("inf")) {
                if(btn->getType().contains("ai")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Infantry","AI",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Infantry","AI",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Infantry","AI",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Infantry","AI",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Infantry","AI",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Infantry","AI",3,false);
                    }
                    else
                        ; //invalid unit type
                }
                else if(btn->getType().contains("at")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Infantry","AT",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Infantry","AT",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Infantry","AT",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Infantry","AT",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Infantry","AT",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Infantry","AT",3,false);
                    }
                    else
                        ; //invalid unit type

                }
                else
                    ; //invalid unit type

            }
            else if(btn->getType().contains("veh")) {
                if(btn->getType().contains("aa")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AA",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AA",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AA",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AA",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AA",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AA",3,false);
                    }
                    else
                        ; //invalid unit type
                }
                else if(btn->getType().contains("ai")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AI",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AI",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AI",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AI",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AI",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AI",3,false);
                    }
                    else
                        ; //invalid unit type
                }
                else if(btn->getType().contains("at")) {
                    if(btn->getType().contains("lv1")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AT",1,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AT",1,false);
                    }
                    else if(btn->getType().contains("lv2")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AT",2,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AT",2,false);
                    }
                    else if(btn->getType().contains("lv3")) {
                        if(btn->getType().contains("red"))
                            spawnUnit("Vehicle","AT",3,true);
                        else if(btn->getType().contains("blue"))
                            spawnUnit("Vehicle","AT",3,false);
                    }
                    else
                        ; //invalid unit type

                }
                else
                    ; //invalid unit type
            }
            else
                ; //invalid unit type
        }
        else if(btn->getType().contains("building")) {

        }
    }
}

void BattleEngine::startCombatSession() {
    cleaner->start(1);
    resourceRound->start(1000);
}

void BattleEngine::connectToInterface(Command *c) {
    connect(c,SIGNAL(clicked()),this,SLOT(commandInterface()));
}

void BattleEngine::endCombatSession() {
    cleaner->stop();
    resourceRound->stop();
}

BattleEngine::~BattleEngine() {
    delete this;
}

